Skip to content

Add ability to use custom serializer and deserializer#125

Merged
bcb merged 1 commit intoexplodinglabs:masterfrom
deptyped:feature/custom-serializer-deserializer
Jul 8, 2020
Merged

Add ability to use custom serializer and deserializer#125
bcb merged 1 commit intoexplodinglabs:masterfrom
deptyped:feature/custom-serializer-deserializer

Conversation

@deptyped
Copy link
Copy Markdown
Contributor

@deptyped deptyped commented Jul 8, 2020

Now all you have to do to change the serialization or deserialization is pass the function to the dispatcher, like this:

import ujson
from flask import Flask, request, Response
from jsonrpcserver import method, dispatch

app = Flask(__name__)


@method
def ping():
    return "pong"


@app.route("/", methods=["POST"])
def index():
    response = dispatch(request.get_data().decode(), serialize=ujson.dumps, deserialize=ujson.loads)
    return Response(str(response), response.http_status, mimetype="application/json")


if __name__ == "__main__":
    app.run()

Copy link
Copy Markdown
Member

@bcb bcb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bcb bcb merged commit 8f3437a into explodinglabs:master Jul 8, 2020
@bcb
Copy link
Copy Markdown
Member

bcb commented Jul 8, 2020

Thanks @deptyped 👌

@deptyped deptyped deleted the feature/custom-serializer-deserializer branch July 8, 2020 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants